﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class administration_ManageCompanies : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void gvCompanies_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        try
        {
            var service = new DBService.Admin.CompanyManager();
            if (service.RemoveCompany((int)e.Keys["CompanyID"]))
            {
                e.Cancel = true;
            }
            else
            {
                throw new Exception();
            }
            gvCompanies.DataBind();
        }
        catch (Exception ex)
        {
            ScriptManager.RegisterClientScriptBlock(this, Page.GetType(), "DeleteError", "alert('Error on deleting, try again or report a bug!')", true);
        }
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        var service = new DBService.Admin.CompanyManager();
        var items = service.GetSearchedCompanies(txtCompanySearchName.Value);
        if (items.Count > 0)
        {
            lblCompNotFound.Visible = false;
            gvCompanies.Visible = true;
            gvCompanies.DataSource = items;
            gvCompanies.DataBind();
        }
        else
        {
            lblCompNotFound.Visible = true;
            gvCompanies.Visible = false;
        }
    }
    protected string GetImageDir()
    {
        return Master.Root + "/upload/";
    }
}